﻿CREATE PROCEDURE [dbo].[BackupDatabase]
	@dbName NVARCHAR(200),
	@backupFile NVARCHAR(MAX)
AS
BEGIN
	DECLARE @query varchar(2000)
	IF EXISTS(SELECT * FROM [master].[dbo].[sysdatabases] WHERE name = @dbName) AND @backupFile IS NOT NULL
	BEGIN
		SET @query = 'BACKUP DATABASE [' + @dbName + '] TO DISK = ' + QUOTENAME(@backupFile, '''') + ' WITH NOFORMAT, INIT, SKIP, NOREWIND, NOUNLOAD, STATS = 10, NAME = N''' + @dbName + ''''
		EXEC (@query)
	END
END